﻿--[[
   @brief    control module for personal_center ui
   @author   dragonqiu
   @version  1.0
   @date     2015-03-18
--]]

personal_center_control =
{
    sub_page2id_url_table = {
        PRIVILEGE_CENTER = {
            id = GAME_ID.GAME_ID_PRIVILEGE_CENTER;
            url = LoadStr("PC_PRIVILEGE_URL");
        };
    };
    
    init = function()
        base_utility.log("[personal_center_control] init");
        ierd_tgp.tpf_ui.Require("personal_center\\model.lua");
        ierd_tgp.tpf_ui.Require("personal_center\\view.lua");
        -- ierd_tgp.tpf_ui.Require("main_top\\control.lua");
        comm_center.reg_service("i_service_personal_center_get_self_info",
            personal_center_control.handle_service_get_self_info);

        comm_center.listen_broadcast("i_broadcast_check_detail",
            personal_center_control.on_handle_check_detail);
    end;

    show_levelup_tips = function()
        local url = LoadStr("LEVEL_UP_TIPS_URL");
        if 0 ~= wegame_mainframe_model.self_tgp_id then
            url = url.."&tgpid="..tostring(wegame_mainframe_model.self_tgp_id);
        end;
        local param = {};
        param.type = "jump_url";
        param.id = GAME_ID.GAEM_ID_HOME_PAGE;
        param.url = url;
        param.op_from = 0;
        local json_str = base_utility.table_to_json(param);
        web_utility.open_link(json_str);
    end;

    show_operated_tips = function()
        layout_mgr.restore_layout("endtips.tpf");
        
        local uilib = ui_utility.uilib();
        local nPopDlg = uilib:GetControlIDbyCustomID(CID_GAMEEND_TIPS_DLG);
        local pControl = uilib:GetControlPtr(nPopDlg);
        local pPopDlg = tolua.cast(pControl, "Tenio::ITDialog");
        local url = personal_center_model.rootUrl..personal_center_model.urlList.popupGameOperate;
        personal_center_control.open_tips_page(uilib, url, CID_GAMEEND_TIPS_QBWEB);
        ierd_tgp.tpf_ui.Log("show priv window success");
        pPopDlg:Show(TRUE);
        pPopDlg:MoveToCenter();
        pPopDlg:BringToTop();
    end;
    
    close_levelup_tips = function()
        local uilib = ui_utility.uilib();
        local nPopDlg = uilib:GetControlIDbyCustomID(CID_PRIV_INFO_DLG);
        if nPopDlg > 0 then
            local pControl = uilib:GetControlPtr(nPopDlg);
            local pPopDlg = tolua.cast(pControl, "Tenio::ITDialog");
            pPopDlg:Show(FALSE);
            layout_mgr.delay_remove_ctrl(nPopDlg);
        end;
    end;

    close_gameend_tips = function()
        local uilib = ui_utility.uilib();
        local nPopDlg = uilib:GetControlIDbyCustomID(CID_GAMEEND_TIPS_DLG);
        if nPopDlg > 0 then
            local pControl = uilib:GetControlPtr(nPopDlg);
            local pPopDlg = tolua.cast(pControl, "Tenio::ITDialog");
            pPopDlg:Show(FALSE);
            layout_mgr.delay_remove_ctrl(nPopDlg);
        end;
    end;

    open_extendboard_privilege_page = function(uilib, param)
        local param = {};
        param.source = "priv_tips";
        param.redirect = "extendboard";--默认为default
        param.type = "personal_center";
        param.sub_page = "MY_PRIVILEGE";
        web_utility.open_link(base_utility.table_to_json(param));
        personal_center_control.close_levelup_tips();
        personal_center_control.close_gameend_tips();
    end;

    open_tips_page = function(uilib, url, cid)
        local nQBWebID = uilib:GetControlIDbyCustomID(cid);
        local pControl = uilib:GetControlPtr(nQBWebID);
        local pQBWeb = tolua.cast(pControl, "Tenio::IQBWebBrowser");
        local const_ui_str, str_holder = 
        U8toCUIStr(url);
        pQBWeb:Navigate(const_ui_str);
    end;

    -- 打开主窗口的个人中心
    open_personal_center_page = function (data_in)
        local param = {};
        param.type ="profile"
        param.tgp_id = data_in.tgp_id
        web_utility.open_link_convert(base_utility.table_to_json(param));
    end;

    --个人中心
    get_personal_info = function(event_ids, json_str)
        local paramTable = base_utility.json_to_table(json_str);
        personal_center_model.player_info = paramTable;
        personal_center_model.uin = paramTable.uin;
        personal_center_control.lua_call_JS("cj_personal_info", json_str);
    end;

    req_personal_info = function(data_in)
        if data_in ~= nil and personal_center_model.player_info ~= nil then
            return personal_center_model.player_info;
        else
            return {};
        end;
    end;
    
    get_sign_in_info = function(event_ids, json_str)
        personal_center_control.lua_call_JS("cj_sign_in_info", json_str);
        if personal_center_model.task_win_id ~= nil then
            local web_id = personal_center_model.task_win_id;
            web_utility.lua_call_js_by_id("cj_sign_in_info", json_str, web_id);
        end;
    end;
    
    get_sign_in = function(event_ids, json_str)
        personal_center_control.lua_call_JS("cj_sign_in", json_str);
        if personal_center_model.task_win_id ~= nil then
            local web_id = personal_center_model.task_win_id;
            web_utility.lua_call_js_by_id("cj_sign_in", json_str, web_id);
        end;
    end;
        
    get_task_com_info = function(event_ids, json_str)
        personal_center_control.lua_call_JS("cj_task_com_info", json_str);
    end;
 
    get_task_list = function(event_ids, json_str)
        ierd_tgp.tpf_ui.Log("get_task_list"..json_str);
        personal_center_control.lua_call_JS("cj_task_list", json_str);
        if personal_center_model.task_win_id ~= nil then
            local web_id = personal_center_model.task_win_id;
            web_utility.lua_call_js_by_id("cj_task_list", json_str, web_id);
        end;
    end;

    get_holly_wood_reward_list = function(event_ids, json_str)
        ierd_tgp.tpf_ui.Log("get_holly_wood_reward_list"..json_str);
        personal_center_control.lua_call_JS("cj_holly_wood_reward_list", json_str);
        if personal_center_model.task_win_id ~= nil then
            local web_id = personal_center_model.task_win_id;
            web_utility.lua_call_js_by_id("cj_holly_wood_reward_list", json_str, web_id);
        end;
    end;

    get_holly_wood_chk_flag = function(event_ids, json_str)
        ierd_tgp.tpf_ui.Log("get_holly_wood_chk_flag"..json_str);
        personal_center_control.lua_call_JS("cj_holly_wood_chk_flag", json_str);
        if personal_center_model.task_win_id ~= nil then
            local web_id = personal_center_model.task_win_id;
            web_utility.lua_call_js_by_id("cj_holly_wood_chk_flag", json_str, web_id);
        end;
    end;

    get_co_act_reward = function(event_ids, json_str)
        if json_str ~= nil then
            ierd_tgp.tpf_ui.Log("get_co_act_reward"..json_str);
            local co_act_table = base_utility.json_to_table(json_str);
            if co_act_table == nil then
                return;
            end;
            if co_act_table["type"] == ierd_tgp.personal_center.PC_COACT_PCGUANJIA then
                personal_center_control.lua_call_JS("cj_qm_software_reward", json_str);
                if personal_center_model.task_win_id ~= nil then
                    local web_id = personal_center_model.task_win_id;
                    web_utility.lua_call_js_by_id("cj_qm_software_reward", json_str, web_id);
                end;
            end;
            if co_act_table["type"] == ierd_tgp.personal_center.PC_COACT_MOBILETGP then
                personal_center_control.lua_call_JS("cj_mobile_tgp_reward", json_str);
                if personal_center_model.task_win_id ~= nil then
                    local web_id = personal_center_model.task_win_id;
                    web_utility.lua_call_js_by_id("cj_mobile_tgp_reward", json_str, web_id);
                end;
            end;
        end;
    end;

    get_co_act_chk_flag = function(event_ids, json_str)
        if json_str ~= nil then
            ierd_tgp.tpf_ui.Log("et_co_act_chk_flag"..json_str);
            local co_act_table = base_utility.json_to_table(json_str);
            if co_act_table == nil then
                return;
            end;
            if co_act_table["type"] == ierd_tgp.personal_center.PC_COACT_PCGUANJIA then
                personal_center_control.lua_call_JS("cj_qm_software_chk_flag", json_str);
                if personal_center_model.task_win_id ~= nil then
                    local web_id = personal_center_model.task_win_id;
                    web_utility.lua_call_js_by_id("cj_qm_software_chk_flag", json_str, web_id);
                end;
            end;
            if co_act_table["type"] == ierd_tgp.personal_center.PC_COACT_MOBILETGP then
                personal_center_control.lua_call_JS("cj_mobile_tgp_chk_flag", json_str);
                if personal_center_model.task_win_id ~= nil then
                    local web_id = personal_center_model.task_win_id;
                    web_utility.lua_call_js_by_id("cj_mobile_tgp_chk_flag", json_str, web_id);
                end;
            end;
        end;
    end;

    get_mobile_tgp_chk_flag = function(event_ids, json_str)
        if json_str ~= nil then
            ierd_tgp.tpf_ui.Log("get_mobile_tgp_chk_flag :"..json_str);
            local co_act_table = base_utility.json_to_table(json_str);
            if co_act_table == nil then
                return;
            end;
            if co_act_table["type"] == ierd_tgp.personal_center.PC_COACT_MOBILETGP then
                personal_center_control.lua_call_JS("cj_mobile_tgp_chk_flag", json_str);
                if personal_center_model.task_win_id ~= nil then
                    local web_id = personal_center_model.task_win_id;
                    web_utility.lua_call_js_by_id("cj_mobile_tgp_chk_flag", json_str, web_id);
                end;
            end;
        end;
    end;

    get_individual_center_my_privilege = function(event_ids, json_str)
        personal_center_model.my_privilege_list = base_utility.json_to_table(json_str);
        personal_center_control.lua_call_JS("cj_individual_center_my_privilege", json_str);
    end;
    

    get_activity_ext = function(event_ids, json_str)
        if personal_center_model.task_win_id ~= nil then
            local web_id = personal_center_model.task_win_id;
            web_utility.lua_call_js_by_id("cj_activity_ext", json_str, web_id);
        end;
    end;
    
    get_task_result = function(event_ids, json_str)
        ierd_tgp.tpf_ui.Log("get_task_result"..json_str);
        personal_center_control.lua_call_JS("cj_task_result", json_str);
    end;
    
    get_activity_task_result = function(event_ids, json_str)
        if personal_center_model.task_win_id ~= nil then
            local web_id = personal_center_model.task_win_id;
            web_utility.lua_call_js_by_id("cj_activity_task_result", json_str, web_id);
        end;
    end;
    
    get_activity_prize_result = function(event_ids, json_str)
        if personal_center_model.task_win_id ~= nil then
            local web_id = personal_center_model.task_win_id;
            web_utility.lua_call_js_by_id("cj_activity_task_result", json_str, web_id);
        end;
    end;

    get_game_runing_state = function(event_id, param)
        local ptable = base_utility.json_to_table(param);
        personal_center_model.game_running_state = ptable.running_state;
    end;
            
    get_user_signature_and_area_info = function (event_ids, json_str)
        base_utility.log("[personal_center_control]get_user_signature_and_area_info:" .. json_str)
        local param_table = base_utility.json_to_table(json_str)
        if personal_center_model.user_info_rsp_data ~= nil and param_table ~= nil then
            if personal_center_model.user_info_rsp_data.rsp_table ~= nil and 
                personal_center_model.user_info_rsp_data.callback_func ~= nil then 
                personal_center_model.user_info_rsp_data.rsp_table.data = {}
                personal_center_model.user_info_rsp_data.rsp_table.data = param_table
                local rsp_json = base_utility.table_to_json(
                    personal_center_model.user_info_rsp_data.rsp_table)
                base_utility.log("[personal_center_control]get_user_signature_and_area_info, rsp_json:"
                    .. rsp_json)
                web_utility.lua_call_js_ex(
                    personal_center_model.user_info_rsp_data.callback_func,
                    rsp_json, CID_MAINFRAME_QBWEB);
            else
                base_utility.log("[personal_center_control]personal_center_model.user_info_rsp_data is nil")
            end
        end
    end;

    get_user_modify_signature_and_area_result = function (event_ids, json_str)
        base_utility.log("[personal_center_control]get_user_modify_signature_and_area_result:"
            .. json_str)
        local param_table = base_utility.json_to_table(json_str)
        if personal_center_model.modify_user_info_rsp_data ~= nil and param_table ~= nil then
            if personal_center_model.modify_user_info_rsp_data.rsp_table ~= nil and
                personal_center_model.modify_user_info_rsp_data.callback_func ~= nil then
                personal_center_model.modify_user_info_rsp_data.rsp_table.data = {}
                personal_center_model.modify_user_info_rsp_data.rsp_table.data = param_table
                local rsp_json = base_utility.table_to_json(
                    personal_center_model.modify_user_info_rsp_data.rsp_table)
                base_utility.log(
                    "[personal_center_control]get_user_modify_signature_and_area_result, rsp_json:"
                    .. rsp_json)
                web_utility.lua_call_js_ex(
                    personal_center_model.modify_user_info_rsp_data.callback_func,
                    rsp_json, CID_MAINFRAME_QBWEB);

                -- 多iframe嵌套，里面iframe拿不到TGP.get回包，这里用comm_center再发一次；
                -- TODO:用户信息更新通知接口后续需要统一
                comm_center.send_broadcast("i_broadcast_userinfo_modify", 
                    personal_center_model.modify_user_info_rsp_data.rsp_table);
                
                -- 修改成功后刷新大界面个人信息
                local is_self = false;
                if param_table.tgp_id ~= "" and TLoginModule.GetTGPID() == param_table.tgp_id then
                    is_self = true;
                elseif login_model.main_uin ~= 0 and param_table.uin == login_model.main_uin then
                    is_self = true;
                end
                if param_table.ret == 0 and is_self then
                    personal_center_control.update_user_base_info();
                end
            else
                base_utility.log("[personal_center_control]personal_center_model.modify_user_info_rsp_data is nil")
            end
        end
    end;

    get_levelup_tips_info = function(event_ids, json_str)
        if personal_center_model.game_running_state > 0 then
            return;
        end;

        ierd_tgp.tpf_ui.Log("show_levelup_tips"..json_str);
        local paramTable = base_utility.json_to_table(json_str);
        if personal_center_model.signIn then
            for i=1, #(paramTable.data) do
                if paramTable.data[i].ptype > 1 then
                    local game_info = banner_model.get_game_base_info(paramTable.data[i].rid);
                    if game_info and game_info.icon_url then
                        paramTable.data[i].icon = game_info.icon_url;
                    else
                        paramTable.data[i].icon = "";
                    end
                end;
            end;
            local tips_data = {};
            tips_data["content"] = LoadStr("PERSON_CENTER_UPLEVEL_BEGIN")
                ..tostring(paramTable.level)
                ..LoadStr("PERSON_CENTER_UPLEVEL_END");
            personal_center_model.new_privilege_list = 
                base_utility.table_to_json(paramTable);
            -- ui_utility.show_tips(LEVEL_UP_POPUP);
            personal_center_control.show_level_up_tips(tips_data);
        end;
    end;
   
    get_gameoperated_tips_info = function(event_ids, json_str)
        ierd_tgp.tpf_ui.Log("show_operated_tips"..json_str);
        local paramTable = base_utility.json_to_table(json_str);
        local game_info = banner_model.get_game_base_info(paramTable.game_id);
        paramTable.game_name = game_info.name;

        if tonumber(paramTable.state) == 1001 then
            local tips_info = base_utility.table_to_json(paramTable);
            personal_center_model.gameadded_tips_info = tips_info;
            GAME_ADDED_POPUP.desc
            = LoadStr("PC_ADDGAME_TIP_BEGIN")
            ..tostring(paramTable.game_name)
            ..LoadStr("PC_ADDGAME_TIP_END");

            if tonumber(paramTable.type) == 0 or tonumber(paramTable.type) == 1 then
                GAME_ADDED_POPUP.desc = LoadStr("PC_ADDGAME_TIP_BODY");
            end;

            ui_utility.show_tips(GAME_ADDED_POPUP);
        elseif tonumber(paramTable.state) == 1002 then
            personal_center_model.gameend_tips_info = base_utility.table_to_json(paramTable);
            personal_center_model.operated_state = paramTable.state;
            personal_center_control.show_operated_tips();
        end;
    end;

    login_success_config = function(event_ids, param)
        personal_center_model.signIn = true;
    end;

    -- ExcecuteJS已废弃，建议使用ExcecuteJSEx，详见web_utility.lua_call_js_ex
    lua_call_JS = function(func_name, json) 
        if wegame_mainframe_model.web_mainframe_ready == false then
            return;
        end
        local nQBWebID = ui_utility.uilib():GetControlIDbyCustomID(CID_MAINFRAME_QBWEB);
        local pControl = ui_utility.uilib():GetControlPtr(nQBWebID);
        local pQBWeb = tolua.cast(pControl, "Tenio::IQBWebBrowser");
        local const_func_name, str_func_name = U8toCUIStr(func_name);
        local const_json_param, str_json_param = U8toCUIStr(json);
        ierd_tgp.tpf_ui.Log("lua_call_JS start.");
        if pQBWeb then
            pQBWeb:ExcecuteJS(const_func_name, const_json_param);
            ierd_tgp.tpf_ui.Log("lua_call_JS success.");
        end;
    end;

    tips_lua_call_JS = function(func_name, json)
        local uilib = ui_utility.uilib();
        local nQBWebID = uilib:GetControlIDbyCustomID(CID_PRIV_INFO_QBWEB);
        local pControl = uilib:GetControlPtr(nQBWebID);
        local pQBWeb = tolua.cast(pControl, "Tenio::IQBWebBrowser");
        local const_func_name, str_func_name = U8toCUIStr(func_name);
        local const_json_param, str_json_param = U8toCUIStr(json);
        ierd_tgp.tpf_ui.Log("lua_call_JS start.");
        if pQBWeb then
            pQBWeb:ExcecuteJS(const_func_name, const_json_param);
            ierd_tgp.tpf_ui.Log("lua_call_JS success.");
        end;
    end;

    gameend_tips_lua_call_JS = function(func_name, json)
        local uilib = ui_utility.uilib();
        local nQBWebID = uilib:GetControlIDbyCustomID(CID_GAMEEND_TIPS_QBWEB);
        local pControl = uilib:GetControlPtr(nQBWebID);
        local pQBWeb = tolua.cast(pControl, "Tenio::IQBWebBrowser");
        local const_func_name, str_func_name = U8toCUIStr(func_name);
        local const_json_param, str_json_param = U8toCUIStr(json);
        ierd_tgp.tpf_ui.Log(func_name..":"..json);
        if pQBWeb then
            pQBWeb:ExcecuteJS(const_func_name, const_json_param);
            ierd_tgp.tpf_ui.Log("lua_call_JS success.");
        end;
    end;

    jc_personal_info = function(uilib, param)
        personal_center_model.get_personal_center():getPersonalInfo();
    end;
    
    jc_player_info = function(uilib, param)
        if personal_center_model.player_info ~= nil then
            personal_center_control.tips_lua_call_JS('cj_player_info', 
                base_utility.table_to_json(personal_center_model.player_info));
        end;
    end;

    jc_sign_in_info = function(uilib, param)
        local ptable = base_utility.json_to_table(param);
        if ptable ~= nil and ptable.web_id ~= nil then
            personal_center_model.task_win_id = ptable.web_id;
        end
        personal_center_model.get_personal_center():getSignInInfo();
    end;

    jc_sign_in = function(uilib, param)
        local ptable = base_utility.json_to_table(param);
        if ptable ~= nil and ptable.web_id ~= nil then
            personal_center_model.task_win_id = ptable.web_id;
        end
        personal_center_model.get_personal_center():signIn();
    end;

    jc_task_com_info = function(uilib, param)
        personal_center_model.get_personal_center():getTaskComInfo();
    end;

    jc_task_list = function(uilib, param)
        local ptable = base_utility.json_to_table(param);
        if ptable ~= nil and ptable.web_id ~= nil then
            personal_center_model.task_win_id = ptable.web_id;
        end
        personal_center_model.get_personal_center():getTaskList();
    end;

    jc_individual_center_my_privilege = function(uilib, param)
        ierd_tgp.tpf_ui.Log("[jc_individual_center_my_privilege]."..param);
        personal_center_model.get_personal_center():getAllPrivInfo();
    end;
    
    jc_holly_wood_reward_list = function(uilib, param)
        ierd_tgp.tpf_ui.Log("[jc_holly_wood_reward_list]."..param);
        local ptable = base_utility.json_to_table(param);
        if ptable ~= nil and ptable.web_id ~= nil then
            personal_center_model.task_win_id = ptable.web_id;
        end
        if ptable ~= nil and ptable.level ~= nil then
            local level = tonumber(ptable.level)
            personal_center_model.get_personal_center():getHollyWoodReward(level);
        end
    end;
    
    jc_blue_diamond_coupon = function(uilib, param)
        ierd_tgp.tpf_ui.Log("[jc_blue_diamond_coupon]."..param);
        local ptable = base_utility.json_to_table(param);
        if ptable ~= nil and ptable.web_id ~= nil then
            personal_center_model.task_win_id = ptable.web_id;
        end
        personal_center_model.get_personal_center():getBlueDiamondCoupon();
    end;
    
    jc_holly_wood_chk_flag = function(uilib, param)
        ierd_tgp.tpf_ui.Log("[jc_holly_wood_chk_flag]."..param);
        local ptable = base_utility.json_to_table(param);
        if ptable ~= nil and ptable.web_id ~= nil then
            personal_center_model.task_win_id = ptable.web_id;
        end
        personal_center_model.get_personal_center():getHollyWoodChkFlag();
    end;
    
    jc_blue_diamond_chk_flag = function(uilib, param)
        ierd_tgp.tpf_ui.Log("[jc_blue_diamond_chk_flag]."..param);
        local ptable = base_utility.json_to_table(param);
        if ptable ~= nil and ptable.web_id ~= nil then
            personal_center_model.task_win_id = ptable.web_id;
        end
        personal_center_model.get_personal_center():getBlueDiamondChkFlag();
    end;

    jc_activity_ext = function(uilib, param)
        local ptable = base_utility.json_to_table(param);
        if ptable ~= nil and ptable.web_id ~= nil then
            personal_center_model.task_win_id = ptable.web_id;
        end
        personal_center_model.get_personal_center():getActivityExt();
    end;
   
    jc_personal_center_open = function(uilib, param)
        personal_center_model.get_personal_center():openPersonalCenter();
    end;

    jc_privilege_change_info = function(uilib, param)
        if personal_center_model.new_privilege_list ~= nil then
            ierd_tgp.tpf_ui.Log("[jc_privilege_change_info]."..personal_center_model.new_privilege_list);
            personal_center_control.tips_lua_call_JS('cj_privilege_change_info', 
                personal_center_model.new_privilege_list);
        end;
    end;

    jc_router_vendor_info = function(event_id, param)
        local device_mgr =
            base_utility.get_component_adapter("IDevice_mgr",
                "ierd_tgp.device.GetDeviceModule();");
        if device_mgr ~= nil then
            local info = ierd_tgp.device.RouterDeviceStatus:new();
            device_mgr:GetRouterStatus(info);
            ierd_tgp.tpf_ui.Log("[huawei]router_vendor="..info.vendor);
            local result;
            if 'xiaomi' == info.vendor then
                result = 1;
            elseif 'huawei' == info.vendor then
                result = 2;
            else
                result = 0;
            end;

            local str = '{"result":' .. tostring(result) .. '}';
            web_utility.lua_call_js('pc_send_route_vendor', str, CID_MAINFRAME_QBWEB);
            info:delete();
        end;
    end;

    jc_gameover_privilege_info = function(uilib, param)
        if personal_center_model.operated_state == 1001 then
            if personal_center_model.gameadded_tips_info ~= nil then
                personal_center_control.gameend_tips_lua_call_JS('cj_gameover_privilege_info',
                personal_center_model.gameadded_tips_info);
            end;
        elseif personal_center_model.operated_state == 1002 then
            if personal_center_model.gameend_tips_info ~= nil then
                personal_center_control.gameend_tips_lua_call_JS('cj_gameover_privilege_info', 
                personal_center_model.gameend_tips_info);
            end;
        end;
    end;
    
    open_link = function(event_id, json_str)
        local json_table = base_utility.json_to_table(json_str);
        if json_table == nil then
            return;
        end;
        
        if json_table.type == "personal_center" then
            local id_and_url = personal_center_control.sub_page2id_url_table[json_table.sub_page];
            if id_and_url == nil then
                id_and_url = personal_center_control.sub_page2id_url_table.PRIVILEGE_CENTER;
            end;
            local params = {};
            params.module_id = id_and_url.id;
            params.module_url = id_and_url.url;
            event_center.send_event(banner_event.JUMP_MODULE_WEB, base_utility.table_to_json(params));
        end;
    end;
    
    check_qm_software_env = function(uilib, param)
        ierd_tgp.tpf_ui.Log("[check_qm_software_env].");
        local pc_type = ierd_tgp.personal_center.PC_COACT_PCGUANJIA;
        if pc_type ~= nil then 
            personal_center_model.get_personal_center():CheckCoActEnv(pc_type);
        end;
    end;
    
    jc_qm_software_chk_flag = function(uilib, param)
        ierd_tgp.tpf_ui.Log("[jc_qm_software_chk_flag].");
        local ptable = base_utility.json_to_table(param);
        if ptable ~= nil and ptable.web_id ~= nil then
            personal_center_model.task_win_id = ptable.web_id;
        end
        local pc_type = ierd_tgp.personal_center.PC_COACT_PCGUANJIA;
        if pc_type ~= nil then 
            local qm_env = personal_center_model.get_personal_center():CheckCoActEnv(pc_type);
            if qm_env == true then
                personal_center_model.get_personal_center():GetCoActChkFlag(pc_type);
            else
                local param_table = {};        
                param_table["result"] = 0;
                param_table["check_flag"] = 2;
                param_table["type"] = pc_type;
                local json_str = base_utility.table_to_json(param_table);
                personal_center_control.lua_call_JS("cj_qm_software_chk_flag", json_str);
                if personal_center_model.task_win_id ~= nil then
                    local web_id = personal_center_model.task_win_id;
                    web_utility.lua_call_js_by_id("cj_qm_software_chk_flag", json_str, web_id);
                end;
            end;
        end;
    end;

    jc_qm_software_reward = function(uilib, param)
        --[[
        ierd_tgp.tpf_ui.Log("[jc_qm_software_reward].");
        local ptable = base_utility.json_to_table(param);
        if ptable ~= nil and ptable.web_id ~= nil then
            personal_center_model.task_win_id = ptable.web_id;
        end
        local pc_type = ierd_tgp.personal_center.PC_COACT_PCGUANJIA;
        if pc_type ~= nil then 
            personal_center_model.get_personal_center():GetCoActReward(pc_type);
        end;
        ]]
    end;

    jc_mobile_tgp_chk_flag = function(uilib, param)
        ierd_tgp.tpf_ui.Log("[jc_mobile_tgp_chk_flag].");
        local ptable = base_utility.json_to_table(param);
        if ptable ~= nil and ptable.web_id ~= nil then
            personal_center_model.task_win_id = ptable.web_id;
        end
        local pc_type = ierd_tgp.personal_center.PC_COACT_MOBILETGP;
        if pc_type ~= nil then 
            personal_center_model.get_personal_center():GetCoActChkFlag(pc_type);
        end;
    end;

    jc_mobile_tgp_reward = function(uilib, param)
        ierd_tgp.tpf_ui.Log("[jc_mobile_tgp_reward].");
        local ptable = base_utility.json_to_table(param);
        if ptable ~= nil and ptable.web_id ~= nil then
            personal_center_model.task_win_id = ptable.web_id;
        end
        local pc_type = ierd_tgp.personal_center.PC_COACT_MOBILETGP;
        if pc_type ~= nil then 
            personal_center_model.get_personal_center():GetCoActReward(pc_type);
        else
            ierd_tgp.tpf_ui.Log("[jc_mobile_tgp_reward]. pc_type is nil");
        end;
    end;

    jc_set_start_list = function(uilib, param)
        local ptable = base_utility.json_to_table(param);
        if ptable ~= nil and ptable.startlist then
            personal_center_model.get_personal_center():SetActivitiesStatus(ptable.startlist);
        end
    end;

    jc_get_start_list = function(uilib, param)
        local ptable = base_utility.json_to_table(param);
        if ptable ~= nil and ptable.web_id ~= nil then
            local startlist = ierd_tgp.personal_center.StartList:new_local();
            personal_center_model.get_personal_center():GetActivitiesStatus(startlist);
            local info = {};
            info.startlist = startlist.szStart_list;
            local json = base_utility.table_to_json(info);
            web_utility.lua_call_js_by_id("cj_get_start_list", json, ptable.web_id);
        end;
    end;

    jc_get_install_state = function(uilib, param)
        ierd_tgp.tpf_ui.Log("[jc_get_install_state].");
        local ptable = base_utility.json_to_table(param);
        if ptable ~= nil and ptable.web_id ~= nil then
            if (banner_model == nil or banner_model.game_base_info_list == nil)then
                return;
            end

            local list = banner_model.game_base_info_list;
            local param_table = {}; 
            for i = 0, (list.count - 1) do
                local game_id = list.game_base_info[i].id;
                local is_installed = list.game_base_info[i].is_installed;
                if tonumber(ptable.game_id) == game_id then
                    param_table.ret = 0;       
                    param_table.data = {}; 
                    param_table.data.game_id = game_id;
                    param_table.data.is_installed = is_installed;
                    break;
                end
            end
            local json = base_utility.table_to_json(param_table);
            web_utility.lua_call_js_by_id("cj_get_install_state", json, ptable.web_id);
        end
    end;

    
    jc_get_user_signature_and_area_info = function(uilib, param)
        base_utility.log("[personal_center_control]jc_get_user_signature_and_area_info :" .. param)
        local tbl = base_utility.json_to_table(param);
        if tbl ~= nil and personal_center_model.personal_center ~= nil then
            if tbl.web_id ~= nil then
                personal_center_model.task_win_id = tbl.web_id;
            end
            if tbl.data ~= nil and tbl.data.uin ~= nil then
                personal_center_model.user_info_rsp_data.callback_func = tbl.callback_func
                personal_center_model.user_info_rsp_data.rsp_table = 
                    web_utility.web_rsp_comm_data(tbl, 0, "")
                personal_center_model.get_personal_center():sendUserBaseInfo(tbl.data.uin)
            else
                base_utility.log("[personal_center_control]jc_get_user_signature_and_area_info uin is nil")
            end
        end
    end;

    jc_save_user_signature_and_area_info = function(uilib, param)
        base_utility.log("[personal_center_control]jc_save_user_signature_and_area_info" .. param);
        local tbl = base_utility.json_to_table(param);
        if tbl ~= nil then
            if tbl.web_id ~= nil then
                personal_center_model.task_win_id = tbl.web_id;
            end
            if tbl.data ~= nil then
                personal_center_model.modify_user_info_rsp_data.callback_func = tbl.callback_func
                personal_center_model.modify_user_info_rsp_data.rsp_table = 
                    web_utility.web_rsp_comm_data(tbl, 0, "")
                personal_center_model.get_personal_center():sendUserBaseInfoModify(
                    base_utility.table_to_json(tbl.data));
                personal_center_model.saved_user_info_data = tbl.data
                if nil ~= personal_center_model.saved_user_info_data 
                and nil ~= personal_center_model.saved_user_info_data.head_pic_url then
                    local sub_str = string.sub(personal_center_model.saved_user_info_data.head_pic_url, 1, 4);
                     if sub_str ~= "http" then
                         personal_center_model.saved_user_info_data.head_pic_url = "https:" .. personal_center_model.saved_user_info_data.head_pic_url;
                     end
                end
            else 
                base_utility.log(
                    "[personal_center_control]jc_save_user_signature_and_area_info param.data is nil")
            end
        end
    end;

    update_user_base_info = function()
        if login_model.main_uin ~= nil 
            and personal_center_model.personal_center ~= nil 
            and personal_center_model.saved_user_info_data ~= nil then
            local param = {}
            param.player_name = personal_center_model.saved_user_info_data.nick_name
            param.head_url = personal_center_model.saved_user_info_data.head_pic_url
            -- main_top_control.update_user_base_info(param)
            comm_center.send_broadcast("i_brdcst_personal_center_update_user_info", param);
        end
    end;

    handle_service_get_self_info = function (data)
        local out_data;
        if nil ~= personal_center_model.player_info then
            out_data = personal_center_model.player_info;
        else
            out_data = {};
        end
        return out_data;
    end;

    update_user_info = function(event_id, json_str)
        if json_str == nil then return end
        local tbl_data = base_utility.json_to_table(json_str);
        comm_center.send_broadcast("i_brdcst_update_user_self_info", tbl_data);
    end;

    show_level_up_tips = function (data)
        if nil == data or nil == data.content then
            base_utility.log(string.format("[handle_show_wegame_online_tips]data is nil"));
            return;
        end
        local tip_data = {};
        tip_data.id = os.time();
        tip_data.tips_main_type = tip_type_constant.MAIN_TYPE_NORMAL;
        tip_data.tips_sub_type = tip_type_constant.sub_type_wegame_level_up;

        -- tips标题
        local title = LoadStr("SOCIAL_FRIEND_ONLINE_TIPS_TITILE");
        tip_data.tips_title = title;

        -- tips主体内容
        tip_data.main_title = data.content;
        tip_data.show_duration = 60 * 60 * 1000;

        tip_data.tips_ok_btn = LoadStr("WEGAME_LEVEL_UP_TIPS_CHECK_DETAIL");
        tip_data.ok_service = "i_broadcast_check_detail";

        comm_center.send_broadcast("i_broadcast_tips_show_com", tip_data);
        tips_reveive_common.tips_qos("wg_common_tip", "client_show", tip_data);
    end;

    on_handle_check_detail = function ()
        personal_center_control.show_levelup_tips();
    end;
};

personal_center_control.init();
